/**
 *  @author Cornelius Huang
 *  
 */
app.directive('aDemand', [function() {
	return {
		restrict: 'AE',
		templateUrl: './views/alineDmd.html',
		scope: {
			dmd: '=?',
			oppId: '=?'
		},
		controller: ['$scope', '$state', 'demandService', 'slideCallbackService', 'cmSlideCacheService', 'editReloadService', function($scope, $state, demandService, slideCallbackService, cmSlideCacheService, editReloadService) {
			
			editReloadService.getPromise.then(function(result) {
				console.log('compinent resolve' + result);
			}, function(result) {
				console.log('compinent reject' + result);
			}, function(result) {
				//console.log('compinent notify' + result);
				demandService.getOneDemand($scope.dmd.dmdId).then(function(result) {
					$scope.dmd = result;
				}, function(result) {
					console.log(result);
				});
			});
			
			$scope.edit = function($event) {
				console.log('edit');
				$state.go('account.demand.edit', {oppId: $scope.oppId, dmdId: $scope.dmd.dmdId});
				console.log($scope.dmd);
				cmSlideCacheService.cmCache = $scope.dmd;
				$event.preventDefault();
				$event.stopPropagation();
			}
			
		}]
	}
}]);